#include<stdio.h>
#include<unistd.h>
#include<sys/types.h>
#include<sys/wait.h>
#include<stdlib.h>
//int execl(const char *path, const char *arg, ...)
//int execv(const char *path, char *const argv[])
//int execlp(const char *file, const char *arg, ...)
//int execle(const char *path, const char *arg, ...,char *const envp[])
//int execve(const char *path, char *const argv[], char *const envp[])
//int execvp(const char *file, char *const argv[]);
int main()
{
    char* argv1[] = {
        "ls","-l",NULL
    };
    char* argv2[] = {"./myexe",NULL};
    char* envp[] = {
        "Mypath: Mango",
        "Name:test",
        NULL
    };
    pid_t id = fork();
    //extern char** environ;
    if(id == 0)
    {
        //execl("/usr/bin/ls","ls","-l",NULL);
        //execv("/usr/bin/ls",argv1);
        //execlp("ls","ls","-l",NULL);
        //execle("./myexe","./myexe",NULL,environ); //使用系统的环境变量
        //execle("./myexe","./myexe",NULL,envp);
        //execve("./myexe",argv2,environ);//使用系统的环境变量
        //execve("./myexe",argv2,envp);
        execvp("ls",argv1);
        printf("hello can you see me ?\n");
        exit(1);
    }
    else if(id > 0)
    {
        int status = 0;
        int ret = waitpid(id,&status,0);
        if(ret > 0)
        {
            printf("等待子进程退出成功,退出码:%d,是否收到信号:%d\n",(status>>8)&0xff,status&0x7f);
        }
    }
    else 
        printf("创建子进程失败\n");
    return 0;
}